<?php
/**
 * Created by PhpStorm.
 * User: liuxiaojie
 * Date: 2019-03-10
 * Time: 22:51
 */

namespace app\ops\controller;


class Type extends Base

{

    function index(){

        $list = db('company_type')->where(['status'=> 1])->order('id desc')->paginate(10);

        $this->assign('list', $list);

        return $this->fetch();

    }

    function delete($id){

        db('company_type')->where(['id'=> $id])->update(['status'=> 0]);

        return success([]);

    }

    function add(){

        if(request()->post()){
            $name = request()->param('name', '');

            if(!$name){

                return fail("NAME_NOT_FOUND");
            }

            $post = [
                'name'=> $name,
            ];

            db('company_type')->insert($post);

            return success([]);

        }else{

            $list = db('company_type')->select();
//            dump($list);
            $this->assign('list', $list);

            return $this->fetch();

        }

    }

}